<template>
  <section class="component case-overview-component">
    <case-overview :data="data" :menuType="menuType" />
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Dependencies } from "~/core/decorator";
import { HomePageService } from '~/services/domain-service/home-page.service';
import CaseOverview from './case-overview.vue'
import { Prop } from 'vue-property-decorator'
@Component({
  components: {
    CaseOverview
  }
})
export default class CaseOverviewComponent extends Vue {
  @Dependencies(HomePageService)
  private homePageService: HomePageService
  @Prop() private menuType

  private data = {
    caseTotalCount: {
      name: "案件总数",
      color: "light-purple",
      value: 0,
      iconName: 'daiwancheng',
      hidden: []
    },
    newlyCaseCount: {
      name: "今日新增案件数量",
      color: "light-green",
      value: 0,
      iconName: 'xinzenganjian',
      hidden: []
    },
    waitCaseTotalCount: {
      name: "催收案件数量",
      color: "light-purple",
      value: 0,
      iconName: 'daiwancheng',
      hidden: []
    },
    outFlowCaseCount: {
      name: "流出案件数量",
      color: "light-blue",
      value: 0,
      iconName: 'liuchu',
      hidden: []
    },
    carTotalCount: {
      name: "在库车辆",
      color: "light-purple",
      value: 0,
      iconName: 'daiwancheng',
      hidden: ['tel-admin', 'legal-admin']
    },
  }

  private updateData() {
    // 今日新增案件数量
    this.homePageService.getTodayInsertCaseCount({ type: this.menuType }).subscribe(
      data => this.data.newlyCaseCount.value = data
    )
    // 催收案件数量
    this.homePageService.getCollectionCaseCount({ type: this.menuType }).subscribe(
      data => this.data.waitCaseTotalCount.value = data
    )
    // 流出案件数量
    this.homePageService.getOutCaseCount({ type: this.menuType }).subscribe(
      data => this.data.outFlowCaseCount.value = data
    )
    // 案件总数
    this.homePageService.getAllCaseCount({ type: this.menuType }).subscribe(
      data => this.data.caseTotalCount.value = data)
    // 在线车库
    if (!this.data.carTotalCount.hidden.includes(this.menuType)) {
      this.homePageService.getAllWarehouseCar({ type: this.menuType }).subscribe(
        data => this.data.carTotalCount.value = data)
    }
  }

  private mounted() {
    this.updateData()
  }
}
</script>

<style lang="less" scoped>
</style>
